///-------------------------------------------------------------------------
//jQuery弹出窗口 By Await [2009-11-22]
//--------------------------------------------------------------------------
/*参数：[可选参数在调用时可写可不写,其他为必写]
----------------------------------------------------------------------------
title:	窗口标题
content:  内容(可选内容为){ text | id | img | url | iframe }
width:	内容宽度
height:	内容高度
drag:  是否可以拖动(ture为是,false为否)
time:	自动关闭等待的时间，为空是则不自动关闭
showbg:	[可选参数]设置是否显示遮罩层(0为不显示,1为显示)
cssName:  [可选参数]附加class名称
------------------------------------------------------------------------*/
//示例: tipsWindown(this.title, "img:" + this.src, "500", "400", "true", "", "true", "img")
//------------------------------------------------------------------------
//simpleWindown("例子","text:例子","500","400","true","3000","0","exa")
//------------------------------------------------------------------------
var showWindown = true;
//var templateSrc = "http://www.mingdizhuangshi.com"; //设置loading.gif路径
var templateSrc = "/App_Themes/Theme2"; //设置loading.gif路径
function tipsWindown(title, content, width, height, drag, time, showbg, cssName) {
    $("#windown-box").remove(); //请除内容
    var width = width >= 950 ? this.width = 950 : this.width = width;     //设置最大窗口宽度
    var height = height >= 527 ? this.height = 527 : this.height = height;  //设置最大窗口高度
    if (showWindown == true) {
        var simpleWindown_html = new String;
        simpleWindown_html = "<div id=\"windownbg\" style=\"height:" + $(document).height() + "px;filter:alpha(opacity=0);opacity:0;z-index: 999901\"></div>";
        simpleWindown_html += "<div id=\"windown-box\">";
        simpleWindown_html += "<div id=\"windown-title\"><h2></h2><span id=\"windown-close\">关闭</span></div>";
        simpleWindown_html += "<div id=\"windown-content-border\"><div id=\"windown-content\"></div></div>";
        simpleWindown_html += "</div>";
        $("body").append(simpleWindown_html);
        show = false;
    }
    contentType = content.substring(0, content.indexOf(":"));
    content = content.substring(content.indexOf(":") + 1, content.length);
    switch (contentType) {
        case "text":
            $("#windown-content").html(content);
            break;
        case "id":
            $("#windown-content").html($("#" + content + "").html());
            break;
        case "img":
            $("#windown-content").ajaxStart(function() {
                $(this).html("<img src='" + templateSrc + "/images/loading.gif' class='loading' />");
            });
            $.ajax({
                error: function() {
                    $("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
                },
                success: function(html) {
                    $("#windown-content").html("<img src=" + content + " alt='' width='640' height='480' />");
                }
            });
            break;
        case "url":
            var content_array = content.split("?");
            $("#windown-content").ajaxStart(function() {
                //$(this).html("<img src='" + templateSrc + "/images/loading.gif' class='loading' />");
                $(this).html("<img src='" + templateSrc + "/App_Themes/Theme2/images/tipswindown/loading.gif' class='loading' />");
            });
            $.ajax({
                type: content_array[0],
                url: content_array[1],
                data: content_array[2],
                error: function() {
                    $("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
                },
                success: function(html) {
                    $("#windown-content").html(html);
                }
            });
            break;
        case "iframe":
            $("#windown-content").ajaxStart(function() {
                $(this).html("<img src='" + templateSrc + "/images/loading.gif' class='loading' />");
            });
            $.ajax({
                error: function() {
                    $("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
                },
                success: function(html) {
                    $("#windown-content").html("<iframe src=\"" + content + "\" width=\"100%\" height=\"" + parseInt(height) + "px" + "\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
                }
            });
    }
    $("#windown-title h2").html(title);
    if (showbg == "true") { $("#windownbg").show(); } else { $("#windownbg").remove(); };
    $("#windownbg").animate({ opacity: "0.5" }, "normal"); //设置透明度
    $("#windown-box").show();
    if (height >= 527) {
        $("#windown-title").css({ width: (parseInt(width) + 22) + "px" });
        $("#windown-content").css({ width: (parseInt(width) + 17) + "px", height: height + "px" });
    } else {
        $("#windown-title").css({ width: (parseInt(width) + 10) + "px" });
        $("#windown-content").css({ width: width + "px", height: height + "px" });
    }
    var cw = document.documentElement.clientWidth, ch = document.documentElement.clientHeight, est = document.documentElement.scrollTop;
    var _version = $.browser.version;
    if (_version == 6.0) {
        $("#windown-box").css({ left: "50%", top: (parseInt((ch) / 2) + est) + "px", marginTop: -((parseInt(height) + 53) / 2) + "px", marginLeft: -((parseInt(width) + 32) / 2) + "px", zIndex: "999999" });
    } else {
        $("#windown-box").css({ left: "50%", top: "50%", marginTop: -((parseInt(height) + 53) / 2) + "px", marginLeft: -((parseInt(width) + 32) / 2) + "px", zIndex: "999999" });
    };
    var Drag_ID = document.getElementById("windown-box"), DragHead = document.getElementById("windown-title");

    var moveX = 0, moveY = 0, moveTop, moveLeft = 0, moveable = false;
    if (_version == 6.0) {
        moveTop = est;
    } else {
        moveTop = 0;
    }
    var sw = Drag_ID.scrollWidth, sh = Drag_ID.scrollHeight;
    DragHead.onmouseover = function(e) {
        if (drag == "true") { DragHead.style.cursor = "move"; } else { DragHead.style.cursor = "default"; }
    };
    DragHead.onmousedown = function(e) {
        if (drag == "true") { moveable = true; } else { moveable = false; }
        e = window.event ? window.event : e;
        var ol = Drag_ID.offsetLeft, ot = Drag_ID.offsetTop - moveTop;
        moveX = e.clientX - ol;
        moveY = e.clientY - ot;
        document.onmousemove = function(e) {
            if (moveable) {
                e = window.event ? window.event : e;
                var x = e.clientX - moveX;
                var y = e.clientY - moveY;
                if (x > 0 && (x + sw < cw) && y > 0 && (y + sh < ch)) {
                    Drag_ID.style.left = x + "px";
                    Drag_ID.style.top = parseInt(y + moveTop) + "px";
                    Drag_ID.style.margin = "auto";
                }
            }
        }
        document.onmouseup = function() { moveable = false; };
        Drag_ID.onselectstart = function(e) { return false; }
    }
    $("#windown-content").attr("class", "windown-" + cssName);
    var closeWindown = function() {
        $("#windownbg").remove();
        $("#windown-box").fadeOut("slow", function() { $(this).remove(); });
    }
    if (time == "" || typeof (time) == "undefined") {
        $("#windown-close").click(function() {
            $("#windownbg").remove();
            $("#windown-box").fadeOut("slow", function() { $(this).remove(); });
        });
    } else {
        setTimeout(closeWindown, time);
    }
}

tipsWindown.close = function () {
    $("#windown-close").click();
}
/*
$(function () {
    
    var html = '<div id="resultTipDiv">';
    html += '<div class="popdiv_huv2">';
    html += '<div class="gxyjd_popdiv">';
    html += '<div id="resultTipContent" /></div>';
    //html += '<div class="exit"><a href="#" class="popdiv_exit"></a></div>';
    html += '</div>';
    html += '</div>';
    html += '</div>';
    $("body").append(html);

    $('#resultTipDiv').dialog({
        bgiframe: true,
        autoOpen: false,
        width: 400,
        height: 150,
        modal: true,
        resizable: false,
        position: 'center',
        stack: true,
        zIndex: 33554001,
        title: "提示",
        draggable: false
    });
    /*
    
    function show() {
    i -= 1;
    document.getElementById('resultTipDivShow').innerHTML = i;
    if (i == 0) {
    window.location.href = 'http://yuelangyc.iteye.com';
    }
    window.setTimeout("show()", 1000);
    }   */
})

$.extend({
    //参数msg:操作成功提示
    //arrLinkBtn:链接数组   如：  var arrLinkBtn = new Array();   arrLinkBtn.push(new Array('alert("aa")', '继续添加')); arrLinkBtn.push(new Array('alert("aa")', '返回列表')); 
    popResultTip: function (msg, arrLinkBtn) {
        var content = "<div>" + msg + "</div><br>";
        content += " <div>";
        if (arrLinkBtn.length > 0) {
            for (var i = 0; i < arrLinkBtn.length; i++) {
                //alert(arrLinkBtn[i][0]);
                content += "<a onclick='" + arrLinkBtn[i][0] + "' href='#'>" + arrLinkBtn[i][1] + "</a><br/>"
            }
        }
        content += " </div><br>";
        content += "<div id='resultTipDivShow'></div> ";
        $("#resultTipContent").html(content);
        var i = 6; //关闭时间秒
        $.show(i);
        $(".ui-dialog-titlebar-close ui-corner-all").remove();
        $("#resultTipDiv").dialog("open");
    },
    show: function (j) {
        j -= 1;
        document.getElementById('resultTipDivShow').innerHTML = "<span style='color:red;font-size:larger'>"+j + "</span>秒钟之后，自动跳转到列表页面<br>";
        if (j == 0) {
            //window.location.href = 'http://yuelangyc.iteye.com';
            parent.tipsWindown.close();
        } 
        // 必须给赋值，因为后续如果单击继续添加的方法中需要终止此计时器
       intSetTimeOutID = window.setTimeout("$.show(" + j + ")", 1000);
    }

});

*/

$(function () {
    /*
    var html = '<div id="resultTipDiv">';
    html += '<div class="popdiv_huv2">';
    html += '<div class="gxyjd_popdiv">';
    html += '<div id="resultTipContent" /></div>';
    //html += '<div class="exit"><a href="#" class="popdiv_exit"></a></div>';
    html += '</div>';
    html += '</div>';
    html += '</div>';
    $("body").append(html);
    */

    var html = "<div  id='resultTipDiv' class='pop_tip_body' style='margin:17px; '>";
    html += "</div> ";
    $("body").append(html);

    $('#resultTipDiv').dialog({
        bgiframe: true,
        autoOpen: false,
        width: 491,
        height: 228,
        modal: true,
        resizable: false,
        position: 'center',
        stack: true,
        zIndex: 33554001,
        title: "提示",
        draggable: false
    });
    /*
    
    function show() {
    i -= 1;
    document.getElementById('resultTipDivShow').innerHTML = i;
    if (i == 0) {
    window.location.href = 'http://yuelangyc.iteye.com';
    }
    window.setTimeout("show()", 1000);
    }   */
})

$.extend({
    //参数msg:操作成功提示
    //arrLinkBtn:链接数组   如：  var arrLinkBtn = new Array();   arrLinkBtn.push(new Array('alert("aa")', '继续添加')); arrLinkBtn.push(new Array('alert("aa")', '返回列表')); 
    popResultTip: function (msg, arrLinkBtn) {
        var html = "<div class='pop_tip_body'>";
        html += "        <table width='100%' border='0' cellspacing='0' cellpadding='0'>";
        html += "             <tr>";
        html += "                 <td align='center' height='60'>";
        if (msg != "")
            html += "                  <div class='tip_success'></div>";
        else
            html += "                  <div class='tip_success'></div>";
        html += "                 </td>";
        html += "             </tr>";
        html += "        </table>";
        html += "        <div class='line_gred' >&nbsp;</div>";
        html += "        <div class='l_h7'></div>";
        html += "        <p style='text-align:left'>接下来您可以：</p>  ";

        html += "        <div class='pop_btn' style='margin-left:15px; margin-right:15px; margin-top:5px'> ";
        if (arrLinkBtn.length > 0) {
            for (var i = 0; i < arrLinkBtn.length; i++) {
                if (i+1==arrLinkBtn.length)
                    html += "<span class='mr16'><input name='input' onclick='" + arrLinkBtn[i][0] + "' type='button' class='common_btn_w69' value='" + arrLinkBtn[i][1] + "'/></span>"
                else
                    html += "<input name='input' onclick='" + arrLinkBtn[i][0] + "' type='button' class='common_btn_w69' value='" + arrLinkBtn[i][1] + "'/>"
               // html += "<a onclick='" + arrLinkBtn[i][0] + "' href='#'>" + arrLinkBtn[i][1] + "</a><br/>"
            }
        }

        html += "        </div> ";
        html += "        <p align='center' class='f12gred' id='resultTipShow'>剩余3秒，系统过3秒钟会自动返回上一个页面</p> ";
        html += "</div> ";

        /*
        var content = "<div>" + msg + "</div><br>";
        content += " <div>";
        if (arrLinkBtn.length > 0) {
            for (var i = 0; i < arrLinkBtn.length; i++) {
                content += "<a onclick='" + arrLinkBtn[i][0] + "' href='#'>" + arrLinkBtn[i][1] + "</a><br/>"
            }
        }
        content += " </div><br>";
        content += "<div id='resultTipShow'></div> ";
        $("#resultTipContent").html(content);
        */
        $("#resultTipDiv").html(html);
        var i = 60; //关闭时间秒
        $.show(i);
        $(".ui-dialog-titlebar-close ui-corner-all").remove();
        $("#resultTipDiv").dialog("open");
    },
    show: function (j) {
        j -= 1;
        document.getElementById('resultTipShow').innerHTML = "<span style='color:red;font-size:larger'>剩余" + j + "</span>，系统过" + j + "秒钟会自动返回上一个页面";
        if (j == 0) {
            parent.tipsWindown.close();
        }
        // 必须给赋值，因为后续如果单击继续添加的方法中需要终止此计时器
        intSetTimeOutID = window.setTimeout("$.show(" + j + ")", 1000);
    }

});


